gameboard.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 13
Bugs 0 Features 0
Metric Value
c 13
b 0
f 0
nc 1
dl 0
loc 12
rs 9.4285
cc 1
nop 2
1
/**
2
 * A module for player.
3
 *
4
 * @module
5
 */
6
"use strict";
7
8
class Gameboard {
9
    /**
10
     * @constructor
11
     *
12
     * @param {int} width - number of cards horizontaly.
13
     * @param {int} height - number of cards verticaly.
14
     */
15
    constructor(width, height) {
16
        this.width = width;
17
        this.height = height;
18
        this.numOfCards = width*height;
19
        this.position = []; // of cards that has flipped
20
        this.cardvalue = []; // of cards that has flipped
21
        this.activeplayer; // nickname of player who´s turn it is
0 ignored issues
show
introduced by
The result of the property access to this.activeplayer is not used.
Loading history...
22
        this.gotpair;
0 ignored issues
show
introduced by
The result of the property access to this.gotpair is not used.
Loading history...
23
        this.pairpositions = [];
24
        this.pairvalues = [];
25
        this.paircolors = [];
26
    }
27
28
    getWidth() {
29
        return this.width;
30
    }
31
32
    getHeight() {
33
        return this.height;
34
    }
35
36
    setWidth(width) {
37
        this.width = width;
38
    }
39
40
    setHeight(height) {
41
        this.height = height;
42
    }
43
44
    setGotPair(gotpair) {
45
        this.gotpair = gotpair;
46
    }
47
48
    addPosition(position) {
49
        this.position.push(position);
50
    }
51
52
    addCardValue(cardvalue) {
53
        this.cardvalue.push(cardvalue);
54
    }
55
56
    addPairPositions(pairpos) {
57
        this.pairpositions.push.apply(this.pairpositions, pairpos);
58
        // console.log("GAMEBOARD: addPairPositions: " + this.pairpositions);
59
    }
60
61
    addPairValues(cardvalue) {
62
        this.pairvalues.push(cardvalue);
63
        this.pairvalues.push(cardvalue);
64
    }
65
66
    addPairColors(colorclass) {
67
        this.paircolors.push(colorclass);
68
        this.paircolors.push(colorclass);
69
    }
70
71
    /**
72
    * Flips all cards back
73
    */
74
    resetCards() {
75
        var pairpositions = this.pairpositions;
76
        var pairvalues = this.pairvalues;
77
78
        this.position = [];
79
        this.position.push.apply(this.position, pairpositions);
80
        this.cardvalue = [];
81
        this.cardvalue.push.apply(this.cardvalue, pairvalues);
82
        // console.log("GAMEBOARD: resetCards - this.position: " + this.position);
83
        // console.log("GAMEBOARD: resetCards - this.pairpositions: " + this.pairpositions);
84
        // console.log("GAMEBOARD: resetCards - this.cardvalue: " + this.cardvalue);
85
        // console.log("GAMEBOARD: resetCards - this.pairpositions: " + this.pairpositions);
86
    }
87
88
    setActivePlayer(player) {
89
        this.activeplayer = player;
90
    }
91
}
92
93
// Export module
94
module.exports = Gameboard;
95